package com.kingyea.mobilepolice.userrole.controller;

import com.kingyea.mobilepolice.userrole.bean.UserRole;
import com.kingyea.mobilepolice.userrole.service.UserRoleService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author Mr.Lin
 * @version v1.0.0
 * @description UserRole 控制层
 * @date Created in 2018-03-30 15:30:02
 */
@RequestMapping(value = "/userRole")
@RestController
public class UserRoleController {

    private static final Logger LOGGER = LoggerFactory.getLogger(UserRoleController.class);

    @Autowired
    private UserRoleService userRoleService;

    /**
     * 查询全部
     *
     * @param
     * @return
     */
    @RequestMapping(method = RequestMethod.GET)
    public List<UserRole> list() throws Exception {
        return userRoleService.search(null);
    }

    /**
     * 通过ID查找对象
     *
     * @param id
     * @return
     */
    @RequestMapping(value = "/{id}", method = RequestMethod.GET)
    public UserRole detail(@PathVariable Integer id) throws Exception {
        return userRoleService.getById(id);
    }

    /**
     * 创建
     *
     * @param userRole
     * @return
     */
    @RequestMapping(method = RequestMethod.POST)
    public UserRole create(@RequestBody UserRole userRole) throws Exception {
        return userRoleService.save(userRole);
    }

    /**
     * 更新
     *
     * @param userRole
     * @return
     */
    @RequestMapping(method = RequestMethod.PUT)
    public UserRole update(@RequestBody UserRole userRole) throws Exception {
        return userRoleService.update(userRole);
    }

    /**
     * 删除
     *
     * @param id
     * @return
     */
    @RequestMapping(value = "/{id}", method = RequestMethod.DELETE)
    public int delete(@PathVariable Integer id) throws Exception {
        return userRoleService.deleteById(id);
    }

}
